// const { ProvidePlugin } = require('webpack');

require('../css/info.less')
let gender = document.querySelector('#gender');
let genderText = document.querySelector('#gender-text');
let brithday = document.querySelector('#brithday');
let brithdayS = document.querySelector('#brithday-s');
let rpj = document.querySelector('#rpj');
let rpjs = document.querySelector('#rpjs');
let dachengshi = document.querySelector('#dachengshi');
let xiaochengshi = document.querySelector('#xiaochengshi');
// 全局变量
let pid =  ''; 
// 性别
gender.addEventListener('click', function () {
    weui.picker([{
        label: '男',
        value: '男'
    }, {
        label: '女',
        value: '女'
    }], {
        onConfirm: function (result) {
            genderText.innerText = result[0].value
        },
        title: '选择性别'
    });
})
// 生日
brithday.addEventListener('click',function(){
    weui.datePicker({
        start: 1920,
        end: new Date().getFullYear(),
        onConfirm:function(result){
            let y = result[0].value;
            let m = result[1].value;
            let d = result[2].value;
            m=m<10?'0'+m:m;
            d=d<10?'0'+d:d;
            brithdayS.innerText = `${y}-${m}-${d}`
        },
        title:'生日'
    });
})
// 省份
rpj.addEventListener('click',function(){
    $http.get('/address/province',{},function(res){
        let dataArr = res.data.map(function(item){
            let obj = {
                label:item.name,
                value:item.addressId
            }
            return obj;
        })
        weui.picker(dataArr,{
            onConfirm: function (result) {
                pid = result[0].value;
                rpjs.textContent = result[0].label
                xiaochengshi.innerHTML ='请选择'
            },
            title: '选择省份'
        })
    })
})
//城市
dachengshi.addEventListener('click',function(){
    if(pid ==''){
        common.toast(0,'请先选择省份');
        return;
    }
    $http.get('/address/city/'+ pid,{},function(res){
        console.log(res.data);
        let cityArr=res.data.map(function(item){
            let obj={
                label:item.name,
                value:item.addressId
            }
            return obj;
        })
        weui.picker(cityArr,{
            onConfirm: function(result){
                xiaochengshi.textContent = result[0].label
            },
            title:'选择城市'
        })
    })
}) 



